﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using GWEB.WebBase.Entity;
using GWEB.WebBase.Utility;
using GWEB.WebFrame.Public;

namespace GWEB.WebFrame.Models
{
    public class SignStudent
    {
        public PageInfo Init()
        {
            PageInfo pg = new PageInfo();
            pg.Type = "SignStudent";
            pg.Title = "学员签到";                       
            pg.SMenuId = "JX03";        
            pg.Condition = "";
            pg.TableName = "cu_customers";
            pg.KeyFieldName = "id";       
            HttpSessionState session = System.Web.HttpContext.Current.Session;
            pg.dict = BasePage.getDict(session);            
            pg.Sop = BasePage.Grant(session, pg.SMenuId);
            pg.Sop.ADD = pg.Sop.EDIT = pg.Sop.DEL = false;
            DataRow drUser = BasePage.GetUser(session);
            String leagueId = Fun.cString(drUser["LeagueId"]);

            String id = "0";
            HttpRequest request = System.Web.HttpContext.Current.Request;
            if (request["id"] != null) id = Fun.cSql(request["id"]);

            String button = "<a href=\"javascript:ShowModalUrl('popEdit', '../Teacher/Leave?Cid=[cid]&ClassName=01&Id=[id]&keyCode='+ GetKeyCode('[id]'), '请假', '', '', '') \"  class='layui-btn layui-btn-xs [btn1Show]'>请假</a>"
                + "<a href=\"javascript:ShowModalUrl('popEdit', '../Main/ManagerLay?type=SelectCourse1&sid=[id]', '调课', '', '', '') \"  class='layui-btn layui-btn-xs [btn1Show]'>调课</a>";

            
            pg.Button.Add("<li onclick=\"GetSelectIds();if(Ids=='') layui.layer.msg('请选择已报名记录！'); else layer.confirm('您确定要签到吗？', function (index) {layer.close(index);Do('../Schedule/SignIn/SignIn',{Ids:Ids,KeyCodes:KeyCodes},true) });\" class='layui-btn layui-btn-normal'><i class='iconfont icon-qdao'></i>签到</li>");
            pg.Button.Add("<li onclick=\"GetSelectIds();if(Ids=='') layui.layer.msg('请选择已报名记录！'); else layer.confirm('您确定要旷课吗？', function (index) {layer.close(index);Do('../Schedule/SignIn/Truancy',{Ids:Ids,KeyCodes:KeyCodes},true) });\" class='layui-btn layui-btn-normal'><i class='iconfont icon-wodeqingjiadan'></i>旷课</li>");
            pg.Button.Add("<li onclick=\"GetSelectIds();if(Ids=='') layui.layer.msg('请选择非报名记录！'); else layer.confirm('您确定要撤销吗？', function (index) {layer.close(index);Do('../Schedule/SignIn/Revoke',{Ids:Ids,KeyCodes:KeyCodes},true) });\" class='layui-btn layui-btn-normal'><i class='iconfont icon-chexiao'></i>撤销</li>");
            pg.Button.Add("<li onclick=\"javascript:ShowModalUrl('popEdit', '../ManagerLay?type=CourseStudent4&id="+id+"', '补课', '', '', '')\" class='layui-btn layui-btn-normal'><i class='iconfont icon-buqian'></i>补课</li>");
           
            pg.Sql = String.Format(@"select * from (
select 
	t2.id,t2.cid,custName,datediff(m,BirdDate,getdate()) custMonth,linkName,custTel,
	AchievementName,IsAuditions,
	case when SignupClass=0 then '正常' else '排队' end SignupClass,
	case t2.state when 0 then '已报名' when 1 then '已签到' when 3 then '旷课' when 4 then '已请假' end	stateCn,
    case when isMakeup=0 then '否' else '是' end isMakeupCn,
    case when t2.state=0 then 'inline-block' else 'none' end as btn1Show,
	'' link
from cu_customers t1
inner join cu_teachercourse_sign t2 on t1.id=t2.cid
where t2.tid={0}
) cu_customers where 1=1 ", id);
            ColumnInfo cl;
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "custName"; cl.HeadText = "宝宝姓名"; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Decimal; cl.FieldName = "custMonth"; cl.HeadText = "月龄";  pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "linkName"; cl.HeadText = "家长姓名";  pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "custTel"; cl.HeadText = "联系电话";  pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "AchievementName"; cl.HeadText = "顾问";  pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "IsAuditions"; cl.HeadText = "学员类型"; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "SignupClass"; cl.HeadText = "上课类型"; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "isMakeupCn"; cl.HeadText = "是否补课"; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "stateCn"; cl.HeadText = "签到状态";pg.AddColumn(cl);

            cl = new ColumnInfo(); cl.FieldName = "link"; cl.HeadText = "操作"; cl.IsSort = false; cl.Script = button; pg.AddColumn(cl);
            return pg;
        }
    }
}